package com.hk.huakangcompany.controller;

import com.alibaba.fastjson.JSON;
import com.hk.huakangcompany.commons.security.CommonResult;
import com.hk.huakangcompany.model.OnlineMessage;
import com.hk.huakangcompany.model.vo.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: aerfazhe
 * @Date: 2021/7/13 9:51
 * @Statement: 网站展示API
 */
@RestController
@RequestMapping("/qiantai")
public class WebsiteController {

    /*@Autowired
    private OnlineMessageService onlineMessageService;*/

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @ApiOperation("在线留言")
    @PostMapping("/onlineMessage")
    public Result onlineMessage(
            @RequestBody OnlineMessage onlineMessage,
            @RequestParam(defaultValue = "a.email") String rk
    ) {
//        存入RabbitMQ中
        String message = JSON.toJSONString(onlineMessage);
        rabbitTemplate.convertAndSend("emailTopicExchange",rk,message);
        Result result = CommonResult.successResult("留言成功！");
        return result;
//        直接存储式留言
        /*int save = onlineMessageService.save(onlineMessage);
        if (save != 1) {
            Result result = CommonResult.nullResult("留言失败！");
            return result;
        }
        Result result = CommonResult.successResult("留言成功！");
        return result;*/
    }



























}
